package xyf.p11.other.twopointer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * ClassName: M1624_NumberSum
 * Description:
 * Author: xyf
 * Date: 9/9/22 10:21 AM
 * Version: 1.0
 **/
public class M1624_NumberSum
{
    public List<List<Integer>> pairSums(int[] nums, int target)
    {
        Arrays.sort(nums);

        int start = 0;
        int end = nums.length - 1;

        List<List<Integer>> res = new ArrayList<>();
        while (start < end)
        {
            int sum = nums[start] + nums[end];
            if (sum == target)
            {
                res.add(Arrays.asList(nums[start], nums[end]));
                start++;
                end--;
            }
            else if (sum < target)
            {
                start++;
            }
            else
            {
                end--;
            }
        }
        return res;
    }
}